package com.lx.idgenerator.autoconfigure;


import com.lx.generator.monitor.TpsThreshold;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author 苏继宙
 * @version V1.0
 * @contact

 */

@ConfigurationProperties(prefix = "id.generator.segment.fetch")
public class SegmentFetchProperties {



    private List<TpsThreshold> tpsThresholds;

    public List<TpsThreshold> getQpsThresholdList() {
        return tpsThresholds;
    }

    public void setQpsThresholdList(List<TpsThreshold> tpsThresholdList) {
        this.tpsThresholds = tpsThresholdList;
    }


    public TpsThreshold getDefaultQpsThreshold() {
        return tpsThresholds.stream()
                .filter(item -> item.getTps() == 0)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("未配置默认的填充策略规则,请检查配置"));
    }





}
